package com.laxcen.smoke.dao;

import com.laxcen.smoke.dto.res.RoleListRes;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface RoleDao {

    @Insert("insert into sys_role(name,description,status,create_time) values(#{name},#{description},#{status},#{createtime})")
    int insert(String name, String description, int status, Date createtime);

    @Insert("insert into sys_role_resources(role_id,resources_id,create_time) values(#{roleid},#{resourcesid},#{createtime})")
    int insertRoleAndResource(long roleid, long resourcesid, Date createtime);

    @Update("update sys_role set name = #{name},description = #{description},available = #{available},update_time = #{updatetime} where id = #{id}")
    int update(String name, String description, int available, Date updatetime, long id);

    @Delete("delete from sys_role where id = #{id}")
    int delete(long id);

    @Delete("delete from sys_role_resources where role_id = #{id}")
    int deleteRoleAndResource(long id);

    @Delete("delete from sys_user_role where role_id = #{id}")
    int deleteRoleAndUser(long id);

    @Select("select id,name,description,available from sys_role")
    List<RoleListRes> getRoleList();

}
